import { fetch } from "../utils/axios";


// 通用公用方法
const req = (method, url, params) => {



    return fetch({
        method: method,
        url: url,
        headers: {
          'Content-Type': 'application/json; charset=UTF-8'
          //'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8'
           // xtoken:storejs.get("token")
        },
        data: params,
       params: params,
        traditional: true,
        transformRequest: [
            function(data) {
                let ret = ''
                for (let it in data) {
                    ret +=
                        encodeURIComponent(it) +
                        '=' +
                        encodeURIComponent(data[it]) +
                        '&'
                }
                return ret
            }
        ]
    }).then(res => {
      return res.data
        //如果服务器验证token已经失效了
        // if(res.data.token===false){
        //     //storejs.remove("userInfo")
        //     //storejs.remove("token")
        //     return res.data
        //
        // }else if(res.data.hasAuthority===false){
        //     //window.location.href = BasisConfig.userCenterUrl+'#/apps/home?err=1'
        // }else{
        //     return res.data
        // }
    });
};



export {
    req
}
